#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include"modform.h"
#include "common.h"

float mod_constant (float ignore1, float ignore2, float ignore3, float ignore4){
	return (float)1;
}

float mod_linear (float t, float it, float ignore1, float ignore2){
	return t/it;
}

float mod_invlinear (float t, float it, float ignore1, float ignore2){
	return (1-(t/it))>0? 1-(t/it) : 0;
}

float mod_sin (float t, float a, float f, float ignore1){
	return 1+a*sin(f*t);
}

float mod_exp (float t, float it, float ignore1, float ignore2){
	return exp(5*(t-it)/it);
}

float mod_invexp (float t, float it, float ignore1, float ignore2){
	return exp(-5*t/it);
}

float mod_quartcos (float t, float it, float ignore1, float ignore2){
	return cos ((PI*t)/(2*it));
}

float mod_quartsin (float t, float it, float ignore1, float ignore2){
	return sin ((PI*t)/(2*it));
}

float mod_halfcos (float t, float it, float ignore1, float ignore2){
	return (1+cos((PI*t)/(it)))/2;
}

float mod_halfsin (float t, float it, float ignore1, float ignore2){
	return (1+sin(PI*(t/it-0.5)))/2;
}

float mod_log (float t, float it, float ignore1, float ignore2){
	return log10(9*t/it+1);
}

float mod_invlog (float t, float it, float ignore1, float ignore2){
	return t<it? log10(-9*t/it+10):0;
}

float mod_tri (float t, float it, float ft, float a){
	return t<ft? t*a/ft:(t-ft)/(ft-it)*(a-1)+a;
}

float mod_pulses (float t, float it, float ft, float a){
	float aux, comp;
	aux=(t/it-floor(t/it))*it;
	comp=abs((1-a)/ft*(aux-it+ft))+a;
	return comp<1 ? comp : 1;
}
